<admintpl file="header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">商品列表</a></li>
        <li><a href="{:U('add')}">新增商品</a></li>
    </ul>
    <form class="well form-search" method="post" action="{:U('index')}" id="export_goods">
        商品名称：
        <input type="text" name="product_name" style="width: 120px;" value="{$formget.product_name}" placeholder="">
        商品ID：
        <input type="text" name="pro_id" style="width: 120px;" value="{$formget.pro_id}" placeholder="">
        状态：
        <select style="width: 75px" id="status" name="status">

            <option value='' <if condition="($formget.status eq '')">selected</if> >全部</option>
            <option value='up' <if condition="($formget.status eq 'up')">selected</if>>上架</option>
            <option value= 'down' <if condition="($formget.status eq  'down')">selected</if>>下架</option>

        </select>


        <input type="submit" style="margin-left: 5px;" class="btn btn-primary" value="搜索"/>
        <!--<input type="button" style="margin-left: 5px;" class="btn btn-primary export_order" value="导出商品"/>-->
    </form>

    <table style="margin-top: 10px;word-break:break-all;" class="table table-hover table-bordered table-list"
           id="menus-table">
        <thead>
        <tr>
            <th>序号</th>
            <th style="white-space: nowrap">商品ID</th>
            <th style="white-space: nowrap">分类</th>
            <th style="white-space: nowrap;width: 200px;">商品名称</th>
            <th style="white-space: nowrap;width: 200px;">封面</th>
            <th>价格</th>
            <th>折后价格</th>
            <th style="white-space: nowrap">虚拟销量</th>
            <th style="white-space: nowrap">销量</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
            <volist name="list" id="vo" key="k">
                <tr>
                    <td>{$k}</td>
                    <td>{$vo.pro_id}</td>
                    <td>{$vo.cate_name}</td>
                    <td>{$vo.product_name}</td>
                    <td><img title="点击查看原图" name="{$vo.cover_photo|setUrl}" src="{$vo.cover_photo|setUrl}?imageView2/2/h/30" onclick="parent.image_preview_dialog(this.name);"</td>
                    <td>{$vo.price}</td>
                    <td>{$vo.sale_price}</td>
                    <td>{$vo.virtual_num}</td>
                    <td>{$vo.sale_num}</td>
                    <td>
                        <if condition="$vo['status'] eq 'up'">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="status"   pro_id={$vo.pro_id} checked value="down"/>上架
                                </label>
                            </div>
                            <else />
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="status"   pro_id="{$vo.pro_id}"  value="up"/>上架
                                </label>
                            </div>
                        </if>
                        <if condition="$vo['hot'] eq 'yes'">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="hot"   pro_id={$vo.pro_id} checked value="no"/>热门
                                </label>
                            </div>
                            <else />
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="hot"   pro_id="{$vo.pro_id}"  value="yes"/>热门
                                </label>
                            </div>
                        </if>
                        <if condition="$vo['if_online'] eq 'yes'">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="if_online"   pro_id={$vo.pro_id} checked value="no"/>在线选号
                                </label>
                            </div>
                            <else />
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="if_online"   pro_id="{$vo.pro_id}"  value="yes"/>在线选号
                                </label>
                            </div>
                        </if>
                    </td>

                    <td>
                        <a href="{:U('edit', ['pro_id' => $vo['pro_id']])}">编辑</a> | <a href="{:U('editAttr', ['pro_id' => $vo['pro_id']])}">编辑属性</a> | <a href="{:U('editPrice', ['pro_id' => $vo['pro_id']])}">编辑价格</a> | <a class="js-ajax-delete" href="{:U('del', ['pro_id' => $vo['pro_id']])}">删除</a>
                    </td>
                </tr>
            </volist>

        </tbody>
    </table>
    <div class="pagination">{$Page}</div>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/jsshowloading.js"></script>
<script>
    $('.export_order').click(function () {
        var form_data = Array();
        form_data.product_name = $("#export_goods :input[name='product_name']").val();
        form_data.id = $("#export_goods :input[name='id']").val();
        form_data.status = $("#export_goods select[name='status']").val();
        form_data.hot = $("#export_goods select[name='hot']").val();
////        console.log(form_data);

        $.ajax({

            url: "{:U('Goods/export_goods')}",
            dataType:"json",
            data:{product_name: form_data.product_name, id: form_data.id, status: form_data.status, hot: form_data.hot
            },
            type:'POST',
            async:true,
            beforeSend:function(){

//                $("body").showLoading();
            },//下面就是获取到的下载地址，直接通过document.location函数获取下载
            success:function(rst){
//                console.log(rst);
                if(rst.code == '210') {
                    alert(rst.msg);return;
                }
                $("body").hideLoading();
//                alert(rst.url);
                document.location.href =(rst.url);

            },
            error: function(){
//                $("body").hideLoading();
                alert("错误");
            },

        });
    });
</script>
<script>
    $('input[type=checkbox]').click(function () {
//        console.log($(this).attr('project_id'));
        var pro_id      = $(this).attr('pro_id');
        var tag_name    =  $(this).attr('name');
        var tag_value   = $(this).attr('value');

        $.post("{:U('setTag')}",{pro_id:pro_id, tag_name: tag_name, tag_value: tag_value},function(data){

            if(data.state == 'success') {
                window.location.reload();
            } else {
                alert(data.state);
            }


        },'json');
    })
</script>
</body>
</html>